package com.edu.nf.main;

import com.edu.nf.entity.Teacher;
import com.edu.nf.handle.SQLExecutor;
import com.edu.nf.implement.BeanHandler;
import com.edu.nf.interfaces.ResultSetHandler;
import com.edu.nf.util.DBUtil;
import com.edu.nf.implement.*;

import java.sql.SQLException;

public class Main {
    public static void main(String[] args) throws SQLException {
        //测试BeanHandler
        String sql="select * from teacher where id=?";
        ResultSetHandler<Teacher> rsh = new BeanHandler(Teacher.class);
        SQLExecutor sqlExecutor = new SQLExecutor(DBUtil.getConnection());
        Teacher teacher = sqlExecutor.executeQuery(sql, rsh, 1);
        System.out.println(teacher.getName());

        //测试BeanListHandler
        /*String sql="select * from teacher";
        AbstractListHandler<Teacher> rsh = new BeanListHandler(Teacher.class);
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        List<Teacher> list = sqlExecutor.executeQuery(sql, rsh);
        for (Teacher t:list) {
            System.out.println(t.getName());
        }*/

        //测试ArrayHandler
        /*String sql="select * from teacher where id=?";
        ResultSetHandler<Object[]> rsh = new ArrayHandler();
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        Object[] objects = sqlExecutor.executeQuery(sql, rsh,2);
        for (int i=0;i<objects.length;i++){
            System.out.println(objects[i]);
        }*/

        //测试ArrayListHandler
        /*String sql="select * from teacher";
        AbstractListHandler<Object[]> rsh = new ArrayListHandler();
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        List<Object[]> objects = sqlExecutor.executeQuery(sql, rsh);
        for (Object[] o:objects){
            for (int i=0;i<o.length;i++){
                System.out.println(o[i]);
            }
        }*/

        //测试MapHandler
        /*String sql="select id,name,sex,age from teacher where id=?";
        ResultSetHandler<Map<String,Object>> rsh = new MapHandler();
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        Map<String, Object> map = sqlExecutor.executeQuery(sql, rsh, 1);
        System.out.println(map.values());*/

        //测试MapListHandler
        /*String sql="select * from teacher";
        AbstractListHandler<Map<String,Object>> rsh = new MapListHandler();
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        List<Map<String, Object>> maps = sqlExecutor.executeQuery(sql, rsh);
        for(Map map:maps){
            System.out.println(map.values());
        }*/

        //测试ColumnHandler
        /*String sql="select * from teacher";
        ResultSetHandler rsh = new ColumnHandler(2);
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        Object teacher = sqlExecutor.executeQuery(sql, rsh);
        System.out.println(teacher);*/

        /**
         * 测试ColumnListHandler
         */
        /*String sql="select * from teacher";
        AbstractListHandler<Object> rsh = new ColumnListHandler(2);
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        List<Object> objects = sqlExecutor.executeQuery(sql, rsh);
        for (Object o:objects){
            System.out.println(o);
        }*/

        //System.out.println("-------------------------------------------");

        //测试更新
        /*String sql="update teacher set name=?,sex=?,age=? where id=?";
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        int i = sqlExecutor.executeUpdate(sql, "样富森", "女", "56", 1);
        System.out.println(i);*/

        //测试插入
        /*String sql="insert into teacher(name,sex,age) values(?,?,?)";
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        int i = sqlExecutor.executeUpdate(sql, "样富森1", "女1", "36");
        System.out.println(i);*/

        //测试删除
        /*String sql="delete from teacher where id=?";
        SQLExecutor sqlExecutor =new SQLExecutor(DBUtil.getConnection());
        int i = sqlExecutor.executeUpdate(sql, 4);
        System.out.println(i);*/
    }
}
